import { _decorator, Component, Node, tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
/** 抖动效果 */
@ccclass('ShakeEffect')
export class ShakeEffect extends Component {

    // 抖动幅度
    @property
    shakeIntensity: number = 10;

    // 抖动持续时间
    @property
    shakeDuration: number = 0.5;

    start() {
        // this.shake();
    }

    shake() {
        const originalPos = this.node.position.clone();

        // 使用 Tween 实现抖动效果
        tween(this.node.position)
            .to(this.shakeDuration / 4, new Vec3(originalPos.x + this.shakeIntensity, originalPos.y, originalPos.z))
            .to(this.shakeDuration / 4, new Vec3(originalPos.x - this.shakeIntensity, originalPos.y, originalPos.z))
            .to(this.shakeDuration / 4, new Vec3(originalPos.x + this.shakeIntensity, originalPos.y, originalPos.z))
            .to(this.shakeDuration / 4, new Vec3(originalPos.x, originalPos.y, originalPos.z))
            .start();
    }
}
